#define DEBUG
#include <cstdio>
#define INF 0x7ffffff
#define MAXN 100000
#define MAXA 2147483647

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class Tree {
public:
  int son[MAXN+1][2], dfn[MAXN+1];

  void remark(int o) {
    if (son[o][0]) {
      remark(son[o][0]);
    }
    dfn[o] = ++dfn[0];
    if (son[o][1]) {
      remark(son[o][1]);
    }
  }
};

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  static Tree tree;
  static int a[MAXN+1], f[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }
  for (int i=2; i<=n; i++) {
    int fa, ch;
    scanf("%d %d", &fa, &ch);
    tree.son[fa][ch] = i;
  }

  tree.remark(1);
  static int map[MAXN+1];
  for (int i=1; i<=n; i++) {
    map[tree.dfn[i]] = i;
  }

  for (int i=1; i<=n; i++) {
    int pos;
    if (f[0]==0 || f[f[0]]<=a[map[i]]-i) {
      pos = ++f[0];
    } else {
      for (int l=1, r=f[0], mid; l<=r; ) {
	mid = (l+r)/2;
	if (f[mid]>a[map[i]]-i) {
	  r = mid-1;
	  pos = mid;
	} else {
	  l = mid+1;
	}
      }
    }
    f[pos] = a[map[i]]-i;
  }

  printf("%d", n-f[0]);

  fcloseall();
  return 0;
}
